<?
set_time_limit(9999999);
/***************************************************************************

*                            Dolphin Smart Community Builder

*                              -----------------

*     begin                : Mon Mar 23 2006

*     copyright            : (C) 2006 BoonEx Group

*     website              : http://www.boonex.com/

* This file is part of Dolphin - Smart Community Builder

*

* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License. 

* http://creativecommons.org/licenses/by/3.0/

*

* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;

* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

* See the Creative Commons Attribution 3.0 License for more details. 

* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin, 

* see license.txt file; if not, write to marketing@boonex.com

***************************************************************************/
 
require_once( 'inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'languages.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'utils.inc.php' );

echo "START .....<br /><br />";

echo "UPDATING DATABASE .....<br /><br />";
 
db_res("UPDATE `sys_modules` SET `version`='2.0.4' WHERE `uri` = 'location' AND `db_prefix` = 'modzzz_location_'");
 
db_res("ALTER TABLE `modzzz_location_review` ADD `sub_id` INT NOT NULL"); 
 
db_res("UPDATE `modzzz_location_review` set `sub_id` = `location_id`");


$aSub = array('event', 'shop', 'hotel', 'nightlife', 'school', 'service', 'transport', 'food');
for ($item = 0; $item < count($aSub)-1; $item++) {
  
	$res = db_res("SELECT `id`, `sub_id` FROM `modzzz_location_review` WHERE `type` = '" . $aSub[$item] . "'");

	while($arr = mysql_fetch_array($res)){
		$iReviewId = (int)$arr['id'];
		$iSubId = (int)$arr['sub_id'];
		$iLocationId = (int)db_value("SELECT `location_id` FROM `modzzz_location_" . $aSub[$item] . "_main` WHERE `id` =" . $iSubId );
		db_res("UPDATE `modzzz_location_review` SET `location_id` = $iLocationId WHERE `id`=$iReviewId");
	}
 
	db_res("DELETE FROM `sys_objects_actions` WHERE `Caption` IN ('{TitleEdit}','{TitleDelete}') AND `Type` = 'modzzz_location_" . $aSub[$item] . "'");


	db_res("
	INSERT INTO `sys_objects_actions` (`Caption`, `Icon`, `Url`, `Script`, `Eval`, `Order`, `Type`) VALUES 
		('{TitleEdit}', 'modules/modzzz/location/|edit.png', '{evalResult}', '', '\$oConfig = \$GLOBALS[''oBxLocationModule'']->_oConfig; return  BX_DOL_URL_ROOT . \$oConfig->getBaseUri() . ''" . $aSub[$item] . "/edit/{ID}'';', '0', 'modzzz_location_" . $aSub[$item] . "'),
		('{TitleDelete}', 'modules/modzzz/location/|action_block.png', '', 'getHtmlData( ''ajaxy_popup_result_div_{ID}'', ''{evalResult}'', false, ''post'');return false;', '\$oConfig = \$GLOBALS[''oBxLocationModule'']->_oConfig; return  BX_DOL_URL_ROOT . \$oConfig->getBaseUri() . ''" . $aSub[$item] . "/delete/{ID}'';', '1', 'modzzz_location_" . $aSub[$item] . "') 
	"); 

}
  



echo "SUCCESSFULLY UPDATED DATABASE ..... <br /><br />";
 

echo "FINISHED <br />";


?>